<% layout('/layouts/default.html', {title: '待办事项列表', libs: ['dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-notebook"></i> ${text('待办事项列表')}
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
                <a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
            </div>
        </div>
        <div class="box-body">
            <#form:form id="searchForm" model="${bizTodoItem}" action="${ctx}/flow/todo/todoListData" method="post" class="form-inline hide"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
                <#form:hidden path="isHandle"/>
                <div class="form-group">
                    <label class="control-label">${text('流程名称')}：</label>
                    <div class="control-inline">
                        <#form:input path="itemName" maxlength="255" class="form-control width-120"/>
                    </div>
                </div>
               <!-- <div class="form-group">
                    <label class="control-label">${text('模块名称')}：</label>
                    <div class="control-inline">
                        <#form:input path="module" maxlength="255" class="form-control width-120"/>
                    </div>
                </div>-->
                <div class="form-group">
                    <label class="control-label">${text('待办人名称')}：</label>
                    <div class="control-inline">
                        <#form:input path="todoUserName" maxlength="255" class="form-control width-120"/>
                    </div>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-search"></i> ${text('查询')}</button>
                    <button type="reset" class="btn btn-default btn-sm isQuick"><i class="glyphicon glyphicon-repeat"></i> ${text('重置')}</button>
                </div>
            </#form:form>
            <table id="dataGrid"></table>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<% } %>
<script>
    //# // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $('#searchForm'),
        columnModel: [
            // {header:'${text("模块名称")}', name:'module', width:90, align:"center"},
            {header:'${text("流程名称")}', name:'itemName', width:270, align:"left", formatter: function(val, obj, row, act) {
                return '<a href="${ctx}/test/leave/flowView?instanceId='+row.instanceId+'" class="btnList" title="${text("请假申请信息")}">'+val+'</a>';
            }},
            {header:'${text("当前环节")}', name:'nodeName', width:120, align:"center"},
            {header:'${text("待办人")}', name:'todoUserName', width:100, align:"center"},
            {header:'${text("通知时间")}', name:'todoTime', width:150, align:"center"},
            {header:'${text("处理人")}', name:'handleUserName', width:100, align:"center"},
            {header:'${text("处理时间")}', name:'handleTime', width:150, align:"center"},
            {header:'${text("操作")}', name:'actions', width:120, align:"left", formatter: function(val, obj, row, act){
                var actions = [];
                if (row.isHandle == 0 && row.nodeName.indexOf('已挂起') === -1) {
                    if (row.nodeName.indexOf('销假') != -1) {
                        actions.push('<a href="javascript:void(0)" onclick="openReportBackModal(\'' + row.taskId + '\',\'' + row.nodeName + '\')" title="${text("请假销假")}"><i class="fa fa-paper-plane-o"></i></a>&nbsp;');
                    } else if(row.nodeName.indexOf('调整') != -1) {
                        actions.push('<a href="javascript:void(0)" onclick="openReportBackModal(\'' + row.taskId + '\',\'' + row.nodeName + '\')" title="${text("重新申请")}"><i class="fa fa-refresh"></i></a>&nbsp;');
                    } else {
                        // 当前登录人不是流程的申请人，可以使用委托审批
                        actions.push('<a href="javascript:void(0)" onclick="openExamineModal(\'' + row.module + '\',\'' + row.taskId + '\')" title="${text("流程办理")}"><i class="fa fa-check-square-o"></i></a>&nbsp;');
                        actions.push('<a href="javascript:void(0)" onclick="openUserModal(\'' + row.taskId + '\')" title="${text("委托审批")}"><i class="fa fa-user-md"></i></a>&nbsp;');
                    }
                } else if (row.isHandle == 1) {
                    actions.push('<a href="javascript:void(0)" onclick="openFlowTrackModal(\'' + row.instanceId + '\')" title="${text("流程追踪")}"><i class="fa fa-history"></i></a>&nbsp;');
                }
                return actions.join('');
            }}
        ],
        //# // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });

    function openExamineModal(module,taskId) {
        let width = '800px', height = '292px';
        js.layer.open({
            type: 2,
            maxmin: true,
            shadeClose: true,
            title: '${text("流程审批")}',
            area: [width, height],
            content: "${ctx}/test/" + module + "/showVerifyDialog?taskId=" + taskId,
            success: function(layero, index){

            }
        });
    }

    function openReportBackModal(taskId,taskName) {
        js.layer.open({
            type: 2,
            maxmin: true,
            shadeClose: true,
            title: taskName,
            area: ['1000px','600px'],
            content: "${ctx}/test/leave/showVerifyDialog?taskId=" + taskId,
            success: function(layero, index){

            }
        });
    }

    function openUserModal(taskId) {
        js.layer.open({
            type: 2,
            maxmin: true,
            shadeClose: true,
            title: '${text("选择委托用户")}',
            area: [(js.layer.$(js.layer.window).width() - 200) + 'px',
                (js.layer.$(js.layer.window).height() - 100) + 'px'],
            content: "${ctx}/flow/user/selectUser?extend.extendS1=" + taskId,
            success: function(layero, index){

            },
            btn: ['<i class="fa fa-check"></i> ${text("确认")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
            btn1: function(index, layero){
                var selectUserCode = $(layero).find("iframe")[0].contentWindow.formData();
                js.confirm('${text("确定要委托给该系统用户吗？")}', function(){
                    if(selectUserCode) {
                        js.ajaxSubmit("${ctx}/flow/process/delegate", {
                            taskId: taskId,
                            delegateToUser: selectUserCode
                        }, function(data) {
                            js.showMessage(data.message);
                            js.window.location.reload();
                        });
                    }
                });

                return true;
            }
        });
    }

    function openFlowTrackModal(instanceId) {
        js.layer.open({
            type: 2,
            maxmin: true,
            shadeClose: true,
            title: '${text("流程追踪")}',
            area: [(js.layer.$(js.layer.window).width() - 200) + 'px',
                (js.layer.$(js.layer.window).height() - 100) + 'px'],
            content: "${ctx}/flow/process/flowTrack?instanceId=" + instanceId,
            success: function(layero, index){

            }
        });
    }
</script>